package com.ziq.zcamp.place

import com.facebook.imagepipeline.request.ImageRequest
import com.zhpan.bannerview.BaseBannerAdapter
import com.zhpan.bannerview.BaseViewHolder
import com.ziq.zcamp.R
import com.ziq.zcamp.bean.post.ImageInfo
import com.ziq.zcamp.util.ImageUtil
import com.ziq.zcamp.view.SafetySimpleDraweeView

class ImageBannerAdapter : BaseBannerAdapter<ImageInfo>() {

    override fun getLayoutId(viewType: Int): Int {
        return R.layout.item_image_banner_crop
    }

    override fun bindData(
        holder: BaseViewHolder<ImageInfo>,
        data: ImageInfo,
        position: Int,
        pageSize: Int
    ) {
        holder.findViewById<SafetySimpleDraweeView>(R.id.image)?.let { imageView ->
            if (data.source?.isNotEmpty() == true){
                ImageUtil.updateImageFromNetwork(imageView, data.source, ImageRequest.CacheChoice.DEFAULT)
            }else{
                ImageUtil.updateImageFromNetwork(imageView, data.url, ImageRequest.CacheChoice.DEFAULT)
            }
        }
    }

}